<?php
class Admin_Forms_ProductForm extends Zend_Form {
	function __construct($option = null) {
		$this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal')
				->setAttrib("id", "add_product_form")
                                ->setAttrib('style','width:90%;float:left');
		$name = $this->createElement('text', 'name');
		$name->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Tên sản phẩm');
		$icon = new Zend_Form_Element_File('file_icon');
		$icon->setLabel('Icon')
				->setDestination(PUBLIC_PATH . '/images/product_data/icons')
				->addValidator('Size', false, '1024KB')
				->setIgnore(true);
//				->setDescription("Nhỏ nhât 96 x 96 px <br />Lớn nhất 512 x 512 px");
		$icon_value = new Zend_Form_Element_Hidden("icon");
		$developer = $this->createElement('text', 'developer');
		$developer->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Nhà phát triển');
		$version = $this->createElement('text', 'version');
		$version->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Phiên bản');
		$size = $this->createElement('text', 'size');
		$size->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Dung lượng');
		$requreiment = $this->createElement('text', 'requreiment');
		$requreiment->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Yêu cầu hệ điều hành');
		$content = $this->createElement ( 'textarea', 'content' );
		$content->setLabel('Viết đánh giá')
				->setAttrib('class', 'input-xlarge ckeditor');
				
		$status = new Zend_Form_Element_Select('status', array(
			'multiOptions' => array("1"	=> "Chạy","0"	=> "Tạm ngừng")
		));
		$status->setLabel("Trạng thái")
				->setAttrib('class', 'form-control');
		$submit = $this->createElement('submit','submit',array ('label' => $option['submit'] ));
		$submit->setAttrib('class', 'btn btn-default')
				->setAttrib("style", "padding: 15px 25px;
										background: #359AFF;
										display: inline-block;
										margin-top: 10px;
										color: #fff;
										text-transform: uppercase;
										font-size: 16px;
										text-decoration: none;");
				
		$type = new Zend_Form_Element_Select('type', array(
			'multiOptions' => array('1'	=> "Game",'2'	=> "Ứng dụng")
		));
		$type->setLabel("Chuyên mục phát hành")
					->setIgnore(TRUE)
					->setAttrib("class", "form-control");
		$category = new Zend_Form_Element_Select('category_id', array(
			'multiOptions' => $option['category_list']
		));
		$category->setAttrib("class", "form-control");
		
		$add_link_download = $this->createElement('html', 'add_link_downlad');
		$add_link_download->setValue("<a id = 'add_link_download'>Thêm link download khác</a>")
						->setLabel("Link download")
						->setIgnore(true);;
						
		$download_link = new Zend_Form_Element_File('file_download_link');
		$download_link->setLabel('File upload')
				->setDestination(PUBLIC_PATH . '/images/product_data/files')
				->addValidator('Size', false, '200MB')
				->setAttrib('multiple', 'multiple')
				->setIgnore(true);
		$download_link_value = new Zend_Form_Element_Hidden("download_link");
		$download_link_value->setDescription("Bạn vui lòng chọn đường dẫn tải game về hoặc upload file cài
												đặt lên hoặc vừa upload cả đường dẫn và file cài đặt");
		$poster = new Zend_Form_Element_File('file_poster');
		$poster->setLabel('Banner quảng cáo')
				->setDestination(PUBLIC_PATH . '/images/product_data/poster')
				->addValidator('Size', false, '1024KB')
				->setIgnore(true);
		$poster_value = new Zend_Form_Element_Hidden("poster");
		
		$ingame_image = new Zend_Form_Element_File('file_ingame_image');
		$ingame_image->setLabel('Ảnh quảng cáo')
				->setDestination(PUBLIC_PATH . '/images/product_data/screenshot')
				->addValidator('Size', false, '1024KB')
				->setAttrib('multiple', 'multiple')
				->setIgnore(true);
		$ingame_image_value = new Zend_Form_Element_Hidden("ingame_image");
		$video = $this->createElement('text', 'video');
		$video->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Link video');
		$this->addElement($name)
				->addElement($developer)
				->addElement($version)
				->addElement($size)
				->addElement($requreiment)
				->addElement($type)
				->addElement($category)
				->addElement($add_link_download)
				->addElement($download_link)
				->addElement($download_link_value)
				->addElement($icon)
				->addElement($icon_value)
				->addElement($poster)
				->addElement($poster_value)
				->addElement($ingame_image)
				->addElement($ingame_image_value)
				->addElement($video)
				->addElement($content)
				->addElement($status)
				->addElement($submit);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'col-md-6')),
										array('label',
											array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'form-group')
		        						)
									)
								);
		$type->setDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'col-md-3')),
										array('label',
											array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'form-group','openOnly'	=> true)
		        						)
									)
								);
		$category->setDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'col-md-3')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'form-group','closeOnly'	=> true)
		        						)
									)
								);
		$submit->setDecorators(array(
								'ViewHelper',
						       ));
		$icon_value->setDecorators(array('ViewHelper'));
		
		$icon->setDecorators(array(
			'File',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'div',"class"	=> "col-md-6")),
			array('label',array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
			array(
				array('row'	=> 'HtmlTag',),
				array('class'=>'form-group ','tag'	=> 'div')
			),
		));
		$poster_value->setDecorators(array('ViewHelper'));
		
		$poster->setDecorators(array(
			'File',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'div',"class"	=> "col-md-6")),
			array('label',array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
			array(
				array('row'	=> 'HtmlTag',),
				array('class'=>'form-group ','tag'	=> 'div')
			),
		));
		$ingame_image_value->setDecorators(array('ViewHelper'));
		
		$ingame_image->setDecorators(array(
			'File',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'div',"class"	=> "col-md-6")),
			array('label',array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
			array(
				array('row'	=> 'HtmlTag',),
				array('class'=>'form-group ','tag'	=> 'div')
			),
		));
		$download_link_value->setDecorators(array('ViewHelper',
													'Description',
													array(	
														array('data'	=> 'HtmlTag'),
														array('tag'		=> 'div','class'	=> 'col-md-8 col-md-offset-3')),
													array(
														array('row'	=> 'HtmlTag',),
														array('class'=>'form-group')
					        						)
		));
		
		$download_link->setDecorators(array(
			'File',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'div',"class"	=> "col-md-6")),
			array('label',array('class'	=> 'col-md-3 control-label','requiredSuffix'=>'*')),
			array(
				array('row'	=> 'HtmlTag',),
				array('class'=>'form-group ','tag'	=> 'div')
			),
		));
//		$download_link->setDecorators(array(
//			'File',
//			'Description',
//			'Errors',
//			array(array('data'=>'HtmlTag'), array('tag' => 'div',"class"	=> "'requiredSuffix'=>'(*)'")),
//			array('label',array('class'	=> 'col-md-2 control-label','requiredSuffix'=>'(*)')),
//			array(
//				array('row'	=> 'HtmlTag',),
//				array('class'=>'form-group ','tag'	=> 'div')
//			),
//		));
//		$download_link_value->setDecorators(array('ViewHelper'));
		
		$this->addDisplayGroup(array('submit',"status"),'action_field');
		$this->addDisplayGroup(array('name','developer','version','size','requreiment',"type","category_id"),'info_field');
		$this->addDisplayGroup(array("add_link_downlad",
										"file_download_link",
										"download_link",
										'file_icon',
										'icon',
										'file_poster',
										'poster',
										'file_ingame_image',
										'ingame_image',
										'video',
		),'file_field');
		$this->addDisplayGroup(array('content'),'content_field');
//		$action = $this->getDisplayGroup('action');
//		$action->setDecorators(array(
//                'FormElements',
//                'Fieldset',
//                array('HtmlTag',array('tag'=>'div','class'	=> ''))
//        ));
	}
}